package pen_exam.danakeji_2023_11_10;

import java.util.Scanner;

public class Class01_SnakeArr {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        if(n == 1){
            System.out.println(1);
        }else{
           int[][] res = proces(n);
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < n; j++) {
                    System.out.print(res[i][j] + " ");
                }
                System.out.println();
            }
        }
    }
   public static int num = 2;
    public static int[][] proces(int n){
        int[][] arr = new int[n][n];
        arr[0][0] = 1;
        arr[n-1][n-1] = n*n;

        int x = 1;
        while(x < n - 1){
            func1(arr,x,n);
            x++;
            func2(arr,x,n);
            x++;
        }
        if(n % 2 == 0){
            func1(arr,x,n);
            x++;
            x = 1;
            //System.out.println(x);
            while (x <  n - 1){
                func3(arr,x,n);
                x++;
                func4(arr,x,n);
                x++;
            }
        }else {
            x = 1;
            //System.out.println(x);
            while (x <  n - 1){
                func4(arr,x,n);
                x++;
                func3(arr,x,n);
                x++;
            }
        }


        return arr;
    }

    public static void func1(int[][] arr,int x,int n){
        //行 / 列 左下斜
        int i = 0;
        int j = x;
        while(i <= x && j >= 0){
            arr[i][j] = num++;
            i++;
            j--;
        }
    }
    public static void func2(int[][] arr,int x,int n){
        //右上斜 列 / 行 右上斜
        int j = 0;
        int i = x;
        while(j <= x && i >= 0){
            arr[i][j] = num++;
            j++;
            i--;
        }
    }

    public static void func3(int[][] arr,int x,int n){
        //行 / 列 左上
        int i = n - 1;
        int j = x;
        while(i >= x  && j <= n - 1){
            arr[i][j] = num++;
            i--;
            j++;
        }
    }
    public static void func4(int[][] arr,int x,int n){
        //右上斜 列 / 行 右下斜
        int j = n - 1;
        int i = x;
        while(j >= x  && i <= n - 1){
            arr[i][j] = num++;
            j--;
            i++;
        }
    }
    public static void func5(int[][] arr,int x,int n){
        //行 / 列 左下
        int i = n - 1;
        int j = x;
        while(i >= x  && j <= n - 1){
            arr[i][j] = num++;
            i--;
            j++;
        }
    }
    public static void func6(int[][] arr,int x,int n){
        //右上斜 列 / 行 右上
        int j = n - 1;
        int i = x;
        while(j >= x  && i <= n - 1){
            arr[i][j] = num++;
            j--;
            i++;
        }
    }
}
